//loading
var images = 0;
var imgNum = 0;
(function(){
	var imagesLoading = [];
	imagesLoading.push("images/fir.png");
	imagesLoading.push("images/max.png");
	imagesLoading.push("images/no.png");
	imagesLoading.push("images/s.png");
	imagesLoading.push("images/star.png");
	for(let i = 1; i < 8;i++){
		imagesLoading.push("images/b-"+i+"");
	}
	for(let i = 1; i < 3;i++){
		imagesLoading.push("images/e-"+i+"");
	}
	for(let i = 1; i < 5;i++){
		imagesLoading.push("images/q-"+i+"");
		imagesLoading.push("images/t-"+i+"");
	}
	imagesLoading.push("images/1.png");
	imagesLoading.push("images/big-r.png");
	imagesLoading.push("images/ss1.png");
	imagesLoading.push("images/panzi.png");
	imagesLoading.push("images/xiong.png");
	imagesLoading.push("images/hui.png");
	
	//开始加载图片
	jQuery.imgpreload(imagesLoading,{
		each: function(data){
			var loadingNum = $('#loadingNum');
			var loadingT = $('#loadingT');
			var status = $(this).data('loaded') ? 'success' : 'error';
		    if (status == "success") {
		    	var v = ((parseFloat(++imgNum) / imagesLoading.length) *100).toFixed(0);
		    	loadingNum.text(v + '%');
		    	loadingT.css('width',v+'%');
		    }
		},
		all: function(){
			// 首页入场动画
			(function init(){
				var boxW = $(window).width();
				$('.xiong-box').css('left',(boxW - 320) / 2);
				$('.shousi').css('left',(boxW - 320) / 2);

				$('.index').show(10,function(){
					$('.title').addClass('z-cx');
					$('.banner').addClass('z-cx');
					$('.bot').addClass('z-cx');
				});
			})();
		}
	});
})();

// 全局函数&变量
(function(){
	var AllHeight = $(window).height();
	var AllWidth = $(window).width();
	var DHeight = document.documentElement.clientHeight;
	var Main = $('.main');

	// 全局宽高
	(function(){
		Main.css({
			'width' : AllWidth,
			'height' : AllHeight
		});

		if(parseInt(AllWidth) == 320){
			$('.fc-ts').addClass('sx5');
		}else{
			$('.fc-ts').addClass('sx');
		}
	})();

	// 横竖屏幕提醒
	(function transverse(){
		if(window.orientation == 90 || window.orientation == -90){
			Main.hide();
			$(".thwartwise").css("display","table-cell");
			$('.thwartwise').width(DHeight);
			$('.thwartwise').height(AllWidth);
	    }else if(window.orientation == 180||window.orientation === 0){
	    	$(".thwartwise").css("display","none");
	    	Main.show();
	    }
	    window.addEventListener("onorientationchange" in window ? "orientationchange" : "resize", transverse, false);
	})();
})();

// 全局禁用屏幕滑动
// (function(){
// 	function JinZhiSX(event) {
// 		event.preventDefault();
// 	}
// 	document.addEventListener('touchmove', JinZhiSX);
// })();


// 各类点击打开关闭
// 第一个参数：点击打开的按钮
// 第二个参数：点击打开的窗口
// 第三个参数：点击关闭窗口
function clickBot(bot,event,close){
	bot.on('click',function(){
		event.fadeIn(400);
	});
	close.on('click',function(){
		event.fadeOut(400);
	})
}


// 取随机数 -- 从0到指定数值
function randomNum(num){
	var randomNum = Math.random() * num;
	var xx = Math.ceil(randomNum);
	xx = xx + 15;
	return xx; // 向上取整
}


// 点击规则
clickBot($('.guize-bot'),$('.guize'),$('.guize'));
// 点击分享和关注
clickBot($('.share-bot'),$('.share'),$('.back'));
clickBot($('.gz-bot'),$('.ewm'),$('.back'));
clickBot($('#ex-tk'),$('.ex-tiaokuan'),$('.ex-tiaokuan'));
clickBot($('#ex-md'),$('.ex-mendian'),$('.ex-close'));

// 显示奖品
function showPirze(num){
	switch(num){
		case 1:
			$('.true').find('.coupon').addClass('one');
			$('.true').find('.coupon').attr('data-prize',1);
			break;
		case 2:
			$('.true').find('.coupon').addClass('two');
			$('.true').find('.coupon').attr('data-prize',2);
			break;
		case 3:
			$('.true').find('.coupon').addClass('three');
			$('.true').find('.coupon').attr('data-prize',3);
			break;
		case 4:
			$('.true').find('.coupon').addClass('four');
			$('.true').find('.coupon').attr('data-prize',4);
			break;
	}
}

// 奖品页面出现
function couponShow(){
	$('.true').fadeIn();
	$('.coupon-box').fadeIn(10,function(){
		$('.title').addClass('coupon-show');
		$('.coupon').addClass('coupon-show');
		$('.bot').addClass('coupon-show');
	})
}

// 奖品的tap切换
(function(){
	$('.vou-b-tap span').on('click', function() {
		var num = $(this).data('num');
		$('.vou-b-body').children('div').eq(num).addClass('active').siblings('div').removeClass('active');
		$(this).addClass('active').siblings('span').removeClass('active');
	});
})();

// 核销码数组

var hxmArr = ['5301','5307','5309','5311','5316','5318','5322','5323','5324',
			  '5329','5330','5335','5336','5337','5339','5340','5341','5304',
			  '5312','5314','5317','5319','5320','5326','5327','5328','5331',
			  '5332','5334','5338','5404','5405','5408','5409','5403','5416',
			  '5415','5801','5802','5803','5851','5852','5853','5854','5876','5903','5904'];

// 验证数组内是否存在指定值
function queryArr(array, item, isSorted) {
	var i = 0, length = array && array.length;
	if (typeof isSorted == 'number') {
		i = isSorted < 0 ? Math.max(0, length + isSorted) : isSorted;
	} else if (isSorted && length) {
		i = _.sortedIndex(array, item);
		return array[i] === item ? i : -1;
	}
	for (; i < length; i++) if (array[i] === item) return i;
	return -1;
};
